//
//  PartySimpleToUnderstandViewController.m
//  homeland
//
//  Created by caesar on 14-8-1.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "PartySimpleToUnderstandViewController.h"
#import "SKSTableView.h"
#import "SKSTableViewCell.h"
#import "PartyImageDetailViewController.h"
#import "ListViewController.h"
#import "FeeManagementViewController.h"
#import "FeeCalculatorViewController.h"

@interface PartySimpleToUnderstandViewController ()
@property (nonatomic, strong) NSArray *contents;


@end

@implementation PartySimpleToUnderstandViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"党务一点通";
    self.tableView.SKSTableViewDelegate = self;
    _contents = @[
                          @[@[@"我要入党", @"积极分子培养流程",@"接收预备党员流程",@"入党宣誓流程",@"预备党员转正流程"]],//0,
    
                          @[@[@"我要转组织关系",@"我要转组织关系"]],//1,
    
                          @[@[@"我要缴纳党费",@"我要缴纳党费",@"党费收缴、使用和管理",@"党费缴纳计算器"]],//2
                          @[@[@"我要参加组织活动",@"我要参加组织活动"]]//3
                          ];
 

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.contents count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.contents[section] count];
}

- (NSInteger)tableView:(SKSTableView *)tableView numberOfSubRowsAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.contents[indexPath.section][indexPath.row] count] - 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SKSTableViewCell";
    
    SKSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell){
        cell = [[SKSTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.textLabel.text = self.contents[indexPath.section][indexPath.row][0];
    UIImage *image = [UIImage imageNamed:@"menu_icon_1.png"];
    cell.imageView.image=image;
    if (indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 2 || indexPath.section == 3 )
        cell.isExpandable = YES;
    else
        cell.isExpandable = NO;
    
    return cell;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForSubRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"UITableViewCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        [cell.textLabel setTextColor:[UIColor orangeColor]];
        
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@", self.contents[indexPath.section][indexPath.row][indexPath.subRow]];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    NSLog(@"tableView %@",tableView.)
    NSLog(@"did   section = %d ,row = %d, subRow = %d  ",indexPath.section,indexPath.row,indexPath.subRow  );
    
    if ((indexPath.section == 0 && indexPath.row >=1)||(indexPath.section == 1 && indexPath.row >=1)||(indexPath.section == 2 && indexPath.row ==1)) {
        //图片展示页
        NSString *name = [NSString stringWithFormat:@"%@", self.contents[indexPath.section][0][indexPath.row]];
        NSLog( @"名称是：%@",name);
        PartyImageDetailViewController *detailVC = [[PartyImageDetailViewController alloc]initWithNibName:@"PartyImageDetailViewController" bundle:nil];
        NSDictionary *dic = @{@"name":name};
        
        detailVC.config = dic;
        [self.navigationController pushViewController:detailVC animated:YES];
    }
    if (indexPath.section == 3 && indexPath.row >=1){
        ListViewController *detailVC = [[ListViewController alloc]initWithNibName:@"ListViewController" bundle:nil];
        detailVC.config = @{@"key":@"志愿最新鲜"};
        [self.navigationController pushViewController:detailVC animated:YES];
    }
    if (indexPath.section == 2 && indexPath.row ==2){
        //党费使用和管理
        FeeManagementViewController *detailVC = [[FeeManagementViewController alloc]initWithNibName:@"FeeManagementViewController" bundle:nil];
        [self.navigationController pushViewController:detailVC animated:YES];
    }
    
    if (indexPath.section == 2 && indexPath.row ==3){
        //计算器
        FeeCalculatorViewController *detailVC = [[FeeCalculatorViewController alloc]initWithNibName:@"FeeCalculatorViewController" bundle:nil];
        [self.navigationController pushViewController:detailVC animated:YES];
    }
}

@end
